package cn.poco.pepsi.util.xmlpared;

import java.io.InputStream;

import org.xmlpull.v1.XmlPullParser;

import android.util.Xml;
import cn.poco.pepsi.bean.Restaurant;

public class GetResByIdXmlparse {
	private static Restaurant resDetailBean = null;

	public static Restaurant getXml(InputStream inSteam) throws Exception {
		XmlPullParser xmpparse = Xml.newPullParser();
		xmpparse.setInput(inSteam, "UTF-8");
		int code = xmpparse.getEventType();
		while (code != XmlPullParser.END_DOCUMENT) {
			switch (code) {
			case XmlPullParser.START_DOCUMENT:
				break;
			case XmlPullParser.START_TAG:
				if ("restaurant".equals(xmpparse.getName())) {
					resDetailBean = new Restaurant();
				}
				if (resDetailBean != null) {
					if ("id".equals(xmpparse.getName())) {
						String id = xmpparse.nextText();
						resDetailBean.setId(Integer.parseInt(id));
					}
					if ("title".equals(xmpparse.getName())) {
						String title = xmpparse.nextText();
						resDetailBean.setTitle(title);
					}
					if ("tel".equals(xmpparse.getName())) {
						String tel = xmpparse.nextText();
						resDetailBean.setTel(tel);
					}
					if ("address".equals(xmpparse.getName())) {
						String address = xmpparse.nextText();
						resDetailBean.setAddress(address);
					}
					if ("vouch".equals(xmpparse.getName())) {
						String vouch = xmpparse.nextText();

						resDetailBean.setVouch(Integer.parseInt(vouch));
					}
					if ("average".equals(xmpparse.getName())) {
						String average = xmpparse.nextText();
						resDetailBean.setAverage(average);
					}
					if ("star".equals(xmpparse.getName())) {
						String star = xmpparse.nextText();
						resDetailBean.setStar(star);
					}
					if ("dish".equals(xmpparse.getName())) {
						String dish = xmpparse.nextText();
						resDetailBean.setDish(dish);
					}
					if ("opening".equals(xmpparse.getName())) {
						String opening = xmpparse.nextText();
						resDetailBean.setOpening(opening);
					}
					if ("traffic".equals(xmpparse.getName())) {
						String traffic = xmpparse.nextText();
						resDetailBean.setTraffic(traffic);
					}
					if ("park".equals(xmpparse.getName())) {
						String park = xmpparse.nextText();
						resDetailBean.setPark(park);
					}
					if ("maindish".equals(xmpparse.getName())) {
						String maindish = xmpparse.nextText();
						resDetailBean.setMaindish(maindish);
					}
					if ("intro".equals(xmpparse.getName())) {
						String intro = xmpparse.nextText();
						resDetailBean.setIntro(intro);
					}
					if ("seat".equals(xmpparse.getName())) {
						String seat = xmpparse.nextText();
						resDetailBean.setSeat(seat);
					}
					if ("location".equals(xmpparse.getName())) {
						String location = xmpparse.nextText();
						resDetailBean.setLocation(location);
					}
					if ("area".equals(xmpparse.getName())) {
						String area = xmpparse.nextText();
						resDetailBean.setArea(area);
					}
					if ("recomment".equals(xmpparse.getName())) {
						String recomment = xmpparse.nextText();
						resDetailBean.setRecomment(recomment);
					}
					if ("discount".equals(xmpparse.getName())) {
						String discount = xmpparse.nextText();
						if (discount != null && !discount.equals("")) {
							resDetailBean.setDiscount(Integer.parseInt(discount));
						}
					}
					if ("comment".equals(xmpparse.getName())) {
						String comment = xmpparse.nextText();
						if (comment != null && !comment.equals("")) {
							resDetailBean.setComment(Integer.parseInt(comment));
						}
					}
					if ("blog-cnt".equals(xmpparse.getName())) {
						String blog = xmpparse.nextText();
						if (blog != null && !blog.equals("")) {
							resDetailBean.setBlog(Integer.parseInt(blog));
						}
					}
					if ("pepsi".equals(xmpparse.getName())) {
						String pepsi = xmpparse.nextText();
						if (pepsi != null && !pepsi.equals("")) {
							resDetailBean.setPepsi(Integer.parseInt(pepsi));
						}
					}
				}
				break;
			}
			code = xmpparse.next();
		}
		inSteam.close();
		System.out.println("KK" + resDetailBean.toString());
		return resDetailBean;
	}
}
